<%--
    Document   : gis-home
    Created on : Feb 18, 2009, 1:37:33 PM
    Author     : Thilani
--%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

    <head>
        <meta http-equiv="Content-Language" content="en-us" />
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Service Oriented Customizable Fr</title>
        <script type="text/javascript" src="OpenLayers.js"></script>


        <style type="text/css">
            .style1 {
                font-size: x-large;
                color: #6600FF;
            }
            .style2 {
                text-align: center;
            }
        </style>
        <style type="text/css">
            #map {
                width: 800px;
                height: 775px;
                border: 1px solid black;
            }
            .style3 {
                text-align: left;
            }
            .style4 {
		color: #5200A4;
	    }
        </style>

    </head>
    <body onload="init()" bgcolor="#DFDFEA"><center>
                <form name="form1" action="GIShome.htm" method="post">
                <input type="hidden" name="myValue" value="http://127.0.0.1/cgi-bin/mapserv.exe?map=/ms4w/apps/ms_ogc_workshop/service/config.map" />

                <%
            String error = "";
            String isSuccessful = "false";
            //read the values from the text boxes
            if (request.getParameter("myValue") != null) {
                if ((request.getParameter("fromCordinate") != null) && (request.getParameter("toCordinate") != null)) {
                    String fromCordinate = request.getParameter("fromCordinate");
                    String toCordinate = request.getParameter("toCordinate");
                    org.shortestpath.core.ui.UiSupport uiSupport = new org.shortestpath.core.ui.UiSupport();
                    uiSupport.processCordinates(fromCordinate, toCordinate);
                    isSuccessful = "true";
                } else {
                    error = "Error in given locations";
                }
            }
              %>
              <input type="hidden" name="pathLayer" value = '<% out.print(isSuccessful.toString().trim()); %>' />

                <script type="text/javascript">
                    var lon = 85;
                    var lat = 3;
                    var zoom = 8;
                    var map, layer, lriver;
                    var mapLocation = document.form1.myValue.value;
                    var pathLayer = document.form1.pathLayer.value;
                    var operationSelect = 0;
                    var panZoomBar = null;
                    var overviewMap = null;
                    var editablePanel = null;
                    var isFromFocussed = false;
                    var isToFocussed = false;

                    function init(){
                        var options = {maxExtent: new OpenLayers.Bounds(7201.366774, 78322.754457, 526493.592543, 541029.724757), maxResolution: 156543, units: 'meters', projection: "EPSG:4015"};
                        map = new OpenLayers.Map( 'map',  options);
                        layer = new OpenLayers.Layer.WMS( "Roads",
                        "http://127.0.0.1/cgi-bin/mapserv.exe?map=/ms4w/Apache/htdocs/map/srilanka.map&service=WMS", {layers: 'Roads'} );

                        layerDist = new OpenLayers.Layer.WMS( "Districts",
                        "http://127.0.0.1/cgi-bin/mapserv.exe?map=/ms4w/Apache/htdocs/map/srilanka.map&service=WMS", {layers: 'Districts', transparent: "TRUE"
                            }, {isBaseLayer: false}
			);

                        if(pathLayer == "true"){
                            layer2 = new OpenLayers.Layer.WMS( "Path",
                            "http://127.0.0.1/cgi-bin/mapserv.exe?map=/ms4w/Apache/htdocs/map/srilanka.map&service=WMS", {layers: 'path', transparent: "TRUE"
                            }, {isBaseLayer: false}
			);
                            map.addLayers([layer, layer2, layerDist]);
                        } else {
                             map.addLayers([layer, layerDist]);
                        }


                        map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
                        map.addControl( new OpenLayers.Control.LayerSwitcher() );

                        map.events.register("click", map, function(e) {
                            var lonlat = map.getLonLatFromViewPortPx(e.xy);
                            applyCordinate (operationSelect, lonlat.lat, lonlat.lon);
                           // alert("You clicked near " + lonlat.lat + " N, " +
                           //           + lonlat.lon + " E");
                        });

                    }

                    function addEditingPanel(cb_value) {
                        if(cb_value == true){
                            vlayer = new OpenLayers.Layer.Vector( "Editable" );
                            map.addLayer(vlayer);
                            var container = document.getElementById("panel");
                            editablePanel = new OpenLayers.Control.EditingToolbar(
                            vlayer, {div: container}
                        );
                            map.addControl(editablePanel);        	}
                        else
                            map.removeControl(editablePanel);
                    }

                    function addPanZoomBar(cb_value) {
                        if(cb_value == true){
                            panZoomBar = new OpenLayers.Control.PanZoomBar();
                            map.addControl(panZoomBar);
                        }
                        else
                            map.removeControl(panZoomBar);

                    }

                    function addOverviewMap(cb_value) {
                        if(cb_value == true){
                            overviewMap = new OpenLayers.Control.OverviewMap();
                            map.addControl(overviewMap);
                        }
                        else
                            map.removeControl(overviewMap);
                    }

                    function setCordinate() {
                        operationSelect = document.getElementById("Select1").selectedIndex;
                    }

                    function setFromFocussed(){
                        isFromFocussed = true;
                        isToFocussed = false;
                    }

                    function setToFocussed() {
                        isToFocussed = true;
                        isFromFocussed = false;
                    }

                    function applyCordinate(select1_value, lat, lon) {
                        if (select1_value == 0) {
                            if (isFromFocussed) {
                                document.form1.fromCordinate.value = lon + "," + lat;
                            }
                            if (isToFocussed) {
                                document.form1.toCordinate.value = lon + "," + lat;
                            }
                        }
                    }

                </script>



                <table border="0" cellpadding="0" cellspacing="0" style="width: 1487px; height: 1003px">
                    <!-- MSTableType="layout" -->
                    <tr>
                        <td valign="top" colspan="3" style="height: 101px" class="style2">
                            <!-- MSCellType="ContentHead" -->
                            <center>
                                <br />
                                <span class="style1">Shortest Path Navigation Application on GIS
                                </span>
                            </center>
                        </td>
                    </tr>
                    <tr>

                        <td msopnltype="NavBody" class="style3">
                            <!-- MSCellType="NavBody" -->
                            <span class="style4">Please select the operation</span><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <select name = "Select1" id="Select1" onchange="setCordinate()">
                            <option>Perform Shorterst Path</option>
                            <option>View Map</option>
                            </select><br><br><br><span class="style4">Please select your location coordinates</span>
                            <br><br>
                            <span class="style4">From</span> <input name="fromCordinate" type="text" onclick="setFromFocussed()"><br>
                            <span class="style4">To</span>&nbsp;&nbsp;&nbsp;&nbsp; <input name="toCordinate" type="text" onclick="setToFocussed()"><br>
                            <br>
                            <br>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <input name="Submit1" type="submit" value="submit">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <input name="Reset1" type="reset" value="reset"><br>
                            <%
                            //read the values from the text boxes
                            out.println(error);
                            %>
                        </td>
                        <td style="height: 136px">&nbsp;</td>
                        <td valign="top" rowspan="3">
                            <div id="map">
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td><span class="style4"><br>Customize your control Panel<br>
                            </span>
                            <input name="checkbox1" type="checkbox" onclick="addPanZoomBar(checkbox1.checked)" class="style4" ><span class="style4">Pan Zoom bar<br>
                            </span>
                            <input name="checkbox2" type="checkbox" onclick="addOverviewMap(checkbox2.checked)" class="style4"><span class="style4">Overview map</span><br>
                        </td>
                        <td style="height: 617px">&nbsp;</td>
                    </tr>
                    <tr>

                        <td msopnltype="NavBody" class="style3">
                        <!-- MSCellType="NavBody" -->&nbsp;</td>
                        <td style="height: 107px">&nbsp;</td>
                    </tr>
                    <tr>

                        <td msopnltype="NavBody" class="style3" colspan="2">
                        <!-- MSCellType="NavBody" -->&nbsp;</td>
                        <td valign="top" style="height: 40px; ">
                        <!-- MSCellType="ContentFoot" -->&nbsp;</td>
                    </tr>
                    <tr>
                        <td style="width: 259px"></td>
                        <td style="width: 65px"></td>
                        <td style="height: 2px; width: 1163px"></td>
                    </tr>
                </table>
            </form>
        </center>
    </body>

</html>
